<template>
  <div class="app-container" v-loading="isSyncLoading" :element-loading-text="isSyncLoadingText">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="fbillno">
        <el-input v-model="queryParams.fbillno" placeholder="请输入单据编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="单据状态" prop="fdocumentStatus">
        <el-select v-model="queryParams.fdocumentStatus" placeholder="请选择单据状态" clearable>
          <el-option v-for="dict in dict.type.mes_workorder_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="fdate">
        <el-date-picker clearable v-model="queryParams.fdate" type="date" value-format="yyyy-MM-dd" placeholder="请选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" @click="synchronizationFunc" size="mini" v-hasPermi="['wms:notice:sync']">同步数据</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['wms:notice:export']">导出</el-button>
      </el-col>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange" height="calc(100vh - 270px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="50px" prop="issueCode">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单据编号" align="center" width="140" prop="fbillno">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{
            scope.row.fbillno }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="日期" align="center" prop="fdate" />
      <el-table-column label="供应商" align="center" prop="vendorName" />
      <el-table-column label="单据状态" align="center" prop="fdocumentStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_workorder_status" :value="scope.row.fdocumentStatus" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="审核状态" align="center" prop="workflowStatus">
        <template slot-scope="scope">
          <span>{{ scope.row.workflowStatus == '0' ? 'SQE审核中' : scope.row.workflowStatus == '1' ? '品质部审核中'
            : scope.row.workflowStatus == '2' ? "审核完成" : "--" }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="SQE审核结果" align="center" prop="sqeAuditResult">
        <template slot-scope="scope">
          <!-- <dict-tag :options="dict.type.mes_workorder_status" :value="scope.row.fdocumentStatus" /> -->
          <span>{{ scope.row.sqeAuditResult == '0' ? '不通过' : scope.row.sqeAuditResult == '1' ? '通过' : "--" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="品质部审核结果" align="center" prop="pzbAuditResult">
        <template slot-scope="scope">
          <!-- <dict-tag :options="dict.type.mes_workorder_status" :value="scope.row.fdocumentStatus" /> -->
          <span>{{ scope.row.pzbAuditResult == '0' ? '不通过' : scope.row.pzbAuditResult == '1' ? '通过' : "--" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建日期" width="155px" align="center" prop="fcreateDate" />
      <el-table-column label="审核日期" width="155px" align="center" prop="fapproveDate" />
      <!-- <el-table-column label="物料编码" align="center" prop="itemCode" />
      <el-table-column label="物料名称" align="center" prop="itemName" />
      <el-table-column label="收料单位" align="center" prop="funitName" />
      <el-table-column label="交货数量" width="120" align="center" prop="jdyFsupdelqty" />-->
      <!-- <el-table-column label="仓库" align="center" prop="fstockName" /> -->
      <!-- <el-table-column label="仓位" align="center" prop="jdyFstocklocid" /> -->
      <!-- <el-table-column label="订单单号" align="center" prop="jdyForderbillno" /> -->
      <!-- <el-table-column label="行状态" align="center" prop="fentrystatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_fentry_status" :value="scope.row.fentrystatus" />
        </template>
      </el-table-column>-->
      <!-- <el-table-column label="旧物料编码" align="center" prop="jdyFreceiverid" /> -->
      <!-- <el-table-column label="申请原因" align="center" prop="jdyFreceiverid" /> -->
      <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="manageQuery(scope.row)" v-if="scope.row.workflowStatus == '0' || scope.row.workflowStatus == '1'" v-hasPermi="['wms:notice:audit']">审核</el-button>
          <!-- v-if="scope.row.workflowStatus == '0' && scope.row.workflowStatus == '1'" -->
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAddpurchasewarehousing(scope.row)"
            v-if="
              scope.row.isFinishQuality == '1' &&
              scope.row.isGenerateWarehousing == '0'
            "
          >生成采购入库单</el-button>-->
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleQuerya(scope.row)" v-if="scope.row.workflowStatus == '2'">采购退料</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['wms:notice:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改收货通知单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="金蝶云fid" prop="jdyFid">
          <el-input v-model="form.jdyFid" placeholder="请输入金蝶云fid" />
        </el-form-item>
        <el-form-item label="金蝶云单据编号" prop="jdyFbillno">
          <el-input v-model="form.jdyFbillno" placeholder="请输入金蝶云单据编号" />
        </el-form-item>
        <el-form-item label="金蝶云收料日期" prop="jdyFdate">
          <el-input v-model="form.jdyFdate" placeholder="请输入金蝶云收料日期" />
        </el-form-item>
        <el-form-item label="金蝶云收料部门" prop="jdyFreceivedeptid">
          <el-input v-model="form.jdyFreceivedeptid" placeholder="请输入金蝶云收料部门" />
        </el-form-item>
        <el-form-item label="金蝶云库存组" prop="jdyFstockgroupid">
          <el-input v-model="form.jdyFstockgroupid" placeholder="请输入金蝶云库存组" />
        </el-form-item>
        <el-form-item label="金蝶云收料员" prop="jdyFreceiverid">
          <el-input v-model="form.jdyFreceiverid" placeholder="请输入金蝶云收料员" />
        </el-form-item>
        <el-form-item label="金蝶云收料组织" prop="jdyFstockorgid">
          <el-input v-model="form.jdyFstockorgid" placeholder="请输入金蝶云收料组织" />
        </el-form-item>
        <el-form-item label="金蝶云需求组织" prop="jdyFdemandorgid">
          <el-input v-model="form.jdyFdemandorgid" placeholder="请输入金蝶云需求组织" />
        </el-form-item>
        <el-form-item label="金蝶云对应组织" prop="jdyFcorrespondorgid">
          <el-input v-model="form.jdyFcorrespondorgid" placeholder="请输入金蝶云对应组织" />
        </el-form-item>
        <el-form-item label="金蝶云采购组织" prop="jdyFpurorgid">
          <el-input v-model="form.jdyFpurorgid" placeholder="请输入金蝶云采购组织" />
        </el-form-item>
        <el-form-item label="金蝶云采购部门" prop="jdyFpurdeptid">
          <el-input v-model="form.jdyFpurdeptid" placeholder="请输入金蝶云采购部门" />
        </el-form-item>
        <el-form-item label="金蝶云采购员" prop="jdyFpurchaserid">
          <el-input v-model="form.jdyFpurchaserid" placeholder="请输入金蝶云采购员" />
        </el-form-item>
        <el-form-item label="金蝶云供应商" prop="jdyFsupplierid">
          <el-input v-model="form.jdyFsupplierid" placeholder="请输入金蝶云供应商" />
        </el-form-item>
        <el-form-item label="金蝶云供货方" prop="jdyFsupplyid">
          <el-input v-model="form.jdyFsupplyid" placeholder="请输入金蝶云供货方" />
        </el-form-item>
        <el-form-item label="金蝶云货主类型" prop="jdyFownertypeidhead">
          <el-input v-model="form.jdyFownertypeidhead" placeholder="请输入金蝶云货主类型" />
        </el-form-item>
        <el-form-item label="金蝶云货主" prop="jdyFowneridhead">
          <el-input v-model="form.jdyFowneridhead" placeholder="请输入金蝶云货主" />
        </el-form-item>
        <el-form-item label="金蝶云确认人" prop="jdyFconfirmerid">
          <el-input v-model="form.jdyFconfirmerid" placeholder="请输入金蝶云确认人" />
        </el-form-item>
        <el-form-item label="金蝶云确认日期" prop="jdyFconfirmdate">
          <el-input v-model="form.jdyFconfirmdate" placeholder="请输入金蝶云确认日期" />
        </el-form-item>
        <el-form-item label="金蝶云外部单据" prop="jdyFisinsidebill">
          <el-input v-model="form.jdyFisinsidebill" placeholder="请输入金蝶云外部单据" />
        </el-form-item>
        <el-form-item label="金蝶云序列号上传" prop="jdyFscanbox">
          <el-input v-model="form.jdyFscanbox" placeholder="请输入金蝶云序列号上传" />
        </el-form-item>
        <el-form-item label="金蝶云变更数量操作" prop="jdyFischangeqty">
          <el-input v-model="form.jdyFischangeqty" placeholder="请输入金蝶云变更数量操作" />
        </el-form-item>
        <el-form-item label="金蝶云物料编码" prop="jdyFmaterialid">
          <el-input v-model="form.jdyFmaterialid" placeholder="请输入金蝶云物料编码" />
        </el-form-item>
        <el-form-item label="金蝶云物料说明" prop="jdyFmaterialdesc">
          <el-input v-model="form.jdyFmaterialdesc" placeholder="请输入金蝶云物料说明" />
        </el-form-item>
        <el-form-item label="金蝶云收料单位" prop="jdyFunitid">
          <el-input v-model="form.jdyFunitid" placeholder="请输入金蝶云收料单位" />
        </el-form-item>
        <el-form-item label="金蝶云交货数量" prop="jdyFactreceiveqty">
          <el-input v-model="form.jdyFactreceiveqty" placeholder="请输入金蝶云交货数量" />
        </el-form-item>
        <el-form-item label="金蝶云预计到货日期" prop="jdyFpredeliverydate">
          <el-input v-model="form.jdyFpredeliverydate" placeholder="请输入金蝶云预计到货日期" />
        </el-form-item>
        <el-form-item label="金蝶云供应商交货数量" prop="jdyFsupdelqty">
          <el-input v-model="form.jdyFsupdelqty" placeholder="请输入金蝶云供应商交货数量" />
        </el-form-item>
        <el-form-item label="金蝶云仓库" prop="jdyFstockid">
          <el-input v-model="form.jdyFstockid" placeholder="请输入金蝶云仓库" />
        </el-form-item>
        <el-form-item label="金蝶云仓位" prop="jdyFstocklocid">
          <el-input v-model="form.jdyFstocklocid" placeholder="请输入金蝶云仓位" />
        </el-form-item>
        <el-form-item label="金蝶云库存状态" prop="jdyFstockstatusid">
          <el-input v-model="form.jdyFstockstatusid" placeholder="请输入金蝶云库存状态" />
        </el-form-item>
        <el-form-item label="金蝶云批号" prop="jdyFlot">
          <el-input v-model="form.jdyFlot" placeholder="请输入金蝶云批号" />
        </el-form-item>
        <el-form-item label="金蝶云拒收原因" prop="jdyFrejectreason">
          <el-input v-model="form.jdyFrejectreason" placeholder="请输入金蝶云拒收原因" />
        </el-form-item>
        <el-form-item label="金蝶云生产日期" prop="jdyFproducedate">
          <el-input v-model="form.jdyFproducedate" placeholder="请输入金蝶云生产日期" />
        </el-form-item>
        <el-form-item label="金蝶云需求部门" prop="jdyFdemanddeptid">
          <el-input v-model="form.jdyFdemanddeptid" placeholder="请输入金蝶云需求部门" />
        </el-form-item>
        <el-form-item label="金蝶云需求人" prop="jdyFdemanderid">
          <el-input v-model="form.jdyFdemanderid" placeholder="请输入金蝶云需求人" />
        </el-form-item>
        <el-form-item label="金蝶云实收数量" prop="jdyFactlandqty">
          <el-input v-model="form.jdyFactlandqty" placeholder="请输入金蝶云实收数量" />
        </el-form-item>
        <el-form-item label="金蝶云合格数量" prop="jdyFreceiveqty">
          <el-input v-model="form.jdyFreceiveqty" placeholder="请输入金蝶云合格数量" />
        </el-form-item>
        <el-form-item label="金蝶云判退数量" prop="jdyFrefuseqty">
          <el-input v-model="form.jdyFrefuseqty" placeholder="请输入金蝶云判退数量" />
        </el-form-item>
        <el-form-item label="金蝶云检验数量" prop="jdyFcheckqty">
          <el-input v-model="form.jdyFcheckqty" placeholder="请输入金蝶云检验数量" />
        </el-form-item>
        <el-form-item label="金蝶云BOM版本" prop="jdyFbomid">
          <el-input v-model="form.jdyFbomid" placeholder="请输入金蝶云BOM版本" />
        </el-form-item>
        <el-form-item label="金蝶云让步接收数量" prop="jdyFcsnreceiveqty">
          <el-input v-model="form.jdyFcsnreceiveqty" placeholder="请输入金蝶云让步接收数量" />
        </el-form-item>
        <el-form-item label="金蝶云确认交货数量" prop="jdyFconfirmdeliqty">
          <el-input v-model="form.jdyFconfirmdeliqty" placeholder="请输入金蝶云确认交货数量" />
        </el-form-item>
        <el-form-item label="金蝶云确认到货日期" prop="jdyFconfirmdelidate">
          <el-input v-model="form.jdyFconfirmdelidate" placeholder="请输入金蝶云确认到货日期" />
        </el-form-item>
        <el-form-item label="金蝶云订单单号" prop="jdyForderbillno">
          <el-input v-model="form.jdyForderbillno" placeholder="请输入金蝶云订单单号" />
        </el-form-item>
        <el-form-item label="金蝶云送货单号" prop="jdyFsendbillno">
          <el-input v-model="form.jdyFsendbillno" placeholder="请输入金蝶云送货单号" />
        </el-form-item>
        <el-form-item label="金蝶云提货单号" prop="jdyFladbillno">
          <el-input v-model="form.jdyFladbillno" placeholder="请输入金蝶云提货单号" />
        </el-form-item>
        <el-form-item label="金蝶云审核日期" prop="jdyFadate">
          <el-input v-model="form.jdyFadate" placeholder="请输入金蝶云审核日期" />
        </el-form-item>
        <el-form-item label="金蝶云实收数量1" prop="jdyFmustqty">
          <el-input v-model="form.jdyFmustqty" placeholder="请输入金蝶云实收数量1" />
        </el-form-item>
        <el-form-item label="金蝶云申请/委外订单号" prop="jdyFTbibText">
          <el-input v-model="form.jdyFTbibText" placeholder="请输入金蝶云申请/委外订单号" />
        </el-form-item>
        <el-form-item label="金蝶云拒收数量" prop="jdyFrejectqty">
          <el-input v-model="form.jdyFrejectqty" placeholder="请输入金蝶云拒收数量" />
        </el-form-item>
        <el-form-item label="金蝶云备注" prop="jdyFnote">
          <el-input v-model="form.jdyFnote" placeholder="请输入金蝶云备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <ReceiptDetails ref="receiptDetails" v-if="openDetail"></ReceiptDetails>
    <CheckDetails ref="checkDetail" v-if="openCheck" @parentList="getList"></CheckDetails>
  </div>
</template>

<script>
import ReceiptDetails from "./receiptDetails.vue";
import CheckDetails from "./checkDetails.vue";
import { selectUserRole } from "@/api/mes/pro/workorder";
import {
  listGoods,
  getGoods,
  delGoods,
  addGoods,
  updateGoods,
  receiveWarehousing,
  synchronization,
  saveToErp
} from "@/api/mes/wm/receiptgoods";
import { addQcIqc } from "@/api/mes/qc/iqc";
import { addItemrecptData } from "@/api/mes/wm/itemrecpt";
import { Row } from "element-ui";

export default {
  name: "Receiptgoods",
  dicts: ["mes_workorder_status", "sys_fentry_status"],
  components: { ReceiptDetails, CheckDetails },
  data() {
    return {
      // 遮罩层
      loading: true,
      openDetail: false,
      openCheck: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收货通知单表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jdyFid: null,
        fbillno: null,
        jdyFdate: null,
        itemCode: null,
        jdyFstockgroupid: null,
        jdyFreceiverid: null,
        jdyFstockorgid: null,
        jdyFdemandorgid: null,
        jdyFcorrespondorgid: null,
        jdyFpurorgid: null,
        jdyFpurdeptid: null,
        jdyFpurchaserid: null,
        jdyFsupplierid: null,
        jdyFsupplyid: null,
        jdyFownertypeidhead: null,
        jdyFowneridhead: null,
        jdyFconfirmerid: null,
        jdyFconfirmdate: null,
        jdyFisinsidebill: null,
        jdyFscanbox: null,
        jdyFischangeqty: null,
        jdyFacctype: null,
        jdyFmaterialid: null,
        jdyFmaterialdesc: null,
        jdyFunitid: null,
        jdyFactreceiveqty: null,
        jdyFpredeliverydate: null,
        jdyFsupdelqty: null,
        jdyFstockid: null,
        jdyFstocklocid: null,
        jdyFstockstatusid: null,
        jdyFlot: null,
        jdyFrejectreason: null,
        jdyFproducedate: null,
        jdyFdemanddeptid: null,
        jdyFdemanderid: null,
        jdyFactlandqty: null,
        jdyFreceiveqty: null,
        jdyFrefuseqty: null,
        jdyFcheckqty: null,
        jdyFbomid: null,
        jdyFcsnreceiveqty: null,
        jdyFconfirmdeliqty: null,
        jdyFconfirmdelidate: null,
        jdyForderbillno: null,
        jdyFsendbillno: null,
        jdyFladbillno: null,
        jdyFadate: null,
        jdyFmustqty: null,
        jdyFTbibText: null,
        jdyFrejectqty: null,
        status: null,
        jdyFnote: null,
        fdocumentStatus: null,
        fdate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      parentId: "",
      isSyncLoading: false,
      isSyncLoadingText: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询收货通知单列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
        // console.log(dict.type.mes_workorder_status,dict.type.mes_workorder_status,"========zidian-======");
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        receiptId: null,
        jdyFid: null,
        jdyFbillno: null,
        jdyFdate: null,
        jdyFreceivedeptid: null,
        jdyFstockgroupid: null,
        jdyFreceiverid: null,
        jdyFstockorgid: null,
        jdyFdemandorgid: null,
        jdyFcorrespondorgid: null,
        jdyFpurorgid: null,
        jdyFpurdeptid: null,
        jdyFpurchaserid: null,
        jdyFsupplierid: null,
        jdyFsupplyid: null,
        jdyFownertypeidhead: null,
        jdyFowneridhead: null,
        jdyFconfirmerid: null,
        jdyFconfirmdate: null,
        jdyFisinsidebill: null,
        jdyFscanbox: null,
        jdyFischangeqty: null,
        jdyFacctype: null,
        jdyFmaterialid: null,
        jdyFmaterialdesc: null,
        jdyFunitid: null,
        jdyFactreceiveqty: null,
        jdyFpredeliverydate: null,
        jdyFsupdelqty: null,
        jdyFstockid: null,
        jdyFstocklocid: null,
        jdyFstockstatusid: null,
        jdyFlot: null,
        jdyFrejectreason: null,
        jdyFproducedate: null,
        jdyFdemanddeptid: null,
        jdyFdemanderid: null,
        jdyFactlandqty: null,
        jdyFreceiveqty: null,
        jdyFrefuseqty: null,
        jdyFcheckqty: null,
        jdyFbomid: null,
        jdyFcsnreceiveqty: null,
        jdyFconfirmdeliqty: null,
        jdyFconfirmdelidate: null,
        jdyForderbillno: null,
        jdyFsendbillno: null,
        jdyFladbillno: null,
        jdyFadate: null,
        jdyFmustqty: null,
        jdyFTbibText: null,
        jdyFrejectqty: null,
        status: null,
        jdyFnote: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.receiptId);
      this.queryParams.wmReceiptGoodsIdList = selection.map(
        item => item.receiptId
      );
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收货通知单";
    },

    /** 生成IQC检验单按钮操作*/
    handleCreateIQC(row) {
      const receiptId = row.receiptId || this.ids;
      getGoods(receiptId).then(response => {
        this.form = response.data;
        console.info("this.form===>", this.form);
        addQcIqc(this.form).then(response => {
          this.$modal.msgSuccess("生成IQC检验单成功");
          this.getList();
        });
      });
    },

    //生成采购入库单接口
    handleAddpurchasewarehousing(row) {
      const receiptId = row.receiptId || this.ids;

      const id = row.id;
      this.$modal
        .confirm("确认执行采购入库？")
        .then(function () {
          return receiveWarehousing(id);
          // return execute(issueIds)//执行入库
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("入库成功");
        })
        .catch(() => { });
      // getGoods(receiptId).then(response => {
      //   this.form = response.data;
      //   console.info("this.form===>", this.form);
      //   addItemrecptData(this.form).then(response => {
      //     this.$modal.msgSuccess("生成采购入库单成功");
      //     this.getList();
      //   });
      // });
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const receiptId = row.receiptId || this.ids;
      getGoods(receiptId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收货通知单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.receiptId != null) {
            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除收货通知单编号为"' + row.fbillno + '"的数据项？')
        .then(function () {
          return delGoods(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 采购退料按钮操作 */
    handleQuerya(row) {
      const id = row.id || this.ids;
      let param = {
        "fbillno": row.fbillno,
        "fid": row.fid
      }
      this.$modal
        .confirm('是否确认采购退料收货通知单编号为"' + row.fbillno + '"的数据项？')
        .then(function () {
          return saveToErp(param);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .catch(() => { });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "mes/wm/receive/export",
        {
          ...this.queryParams
        },
        `goods_${new Date().getTime()}.xlsx`
      );
    },
    /** 同步按钮操作 */
    synchronizationFunc() {
      this.isSyncLoading = true
      this.isSyncLoadingText = '正在同步中，请稍后……'
      let param = {}
      if (this.queryParams.fbillno) {
        param.fbillNo = this.queryParams.fbillno
      }
      synchronization(param).then(response => {
        this.isSyncLoading = false
        this.$modal.msgSuccess("同步来料通知单成功");
        this.getList();
      }).catch(() => {
        this.isSyncLoading = false
      });
    },
    handleView(row) {
      // this.parentId = row.receiptId;
      // console.log(this.parentId);
      // this.$refs.receiptDetails.showFlag = true;
      this.openDetail = true;
      this.$nextTick(() => {
        this.$refs.receiptDetails.init(row);
      });
    },

    handleCheck(row) {
      // this.parentId = row.receiptId;
      // console.log(this.parentId);
      // this.$refs.receiptDetails.showFlag = true;
      this.openCheck = true;
      this.$nextTick(() => {
        this.$refs.checkDetail.init(row);
      });
    },
    // manage
    manageQuery(row) {
      // sqesh    pzbsh
      let name =
        row.workflowStatus == "0"
          ? "SQE审核"
          : row.workflowStatus == "1"
            ? "品质部审核"
            : null;
      if (name) {
        selectUserRole(name)
          .then(res => {
            this.handleCheck(row);
          })
          .catch(() => {
            //  this.$modal.msgError("此用户暂时没有权限");
            return "false";
          });
      } else {
        this.$modal.msgError("该通知单不需要审核！！！");
      }
    }
  }
};
</script>
